<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>C++OJ环境搭建 | jzhmcoo1</title><meta name="keywords" content="OJ,C++"><meta name="author" content="lixing"><meta name="copyright" content="lixing"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="由于之后可能要去复试机考，平时开发时用的都是前端和Node的一套，现在有必要把cpp捡起来了，本文将使用VSCode在MacOS上的cpp17开发环境，以及一些常用的stl和一些常用操作。 环境搭建首先要装Xcode，这里就略了 VSCode安装插件 microsoft&#x2F;vscode-cpptools: Official repository for the Microsoft C&#x2F;C++ ext">
<meta property="og:type" content="article">
<meta property="og:title" content="C++OJ环境搭建">
<meta property="og:url" content="https://www.lihangzhu.com/2021/06/21/Cpp-OJ-Environment/index.html">
<meta property="og:site_name" content="jzhmcoo1">
<meta property="og:description" content="由于之后可能要去复试机考，平时开发时用的都是前端和Node的一套，现在有必要把cpp捡起来了，本文将使用VSCode在MacOS上的cpp17开发环境，以及一些常用的stl和一些常用操作。 环境搭建首先要装Xcode，这里就略了 VSCode安装插件 microsoft&#x2F;vscode-cpptools: Official repository for the Microsoft C&#x2F;C++ ext">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://jzhmcoo1-1258918430.cos.ap-shanghai.myqcloud.com/markdown/20210621082947.png">
<meta property="article:published_time" content="2021-06-21T00:28:12.000Z">
<meta property="article:modified_time" content="2021-06-21T00:28:15.000Z">
<meta property="article:author" content="lixing">
<meta property="article:tag" content="OJ">
<meta property="article:tag" content="C++">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://jzhmcoo1-1258918430.cos.ap-shanghai.myqcloud.com/markdown/20210621082947.png"><link rel="shortcut icon" href="/images/favicon.png"><link rel="canonical" href="https://www.lihangzhu.com/2021/06/21/Cpp-OJ-Environment/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><meta name="google-site-verification" content="pcqGakY4hww-Mg9iGN4mQw6v_y_IRvYmM1l50SAcPpg"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isanchor: true
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-06-21 08:28:15'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
          const isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
          const isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
          const hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified

          if (t === undefined) {
            if (isLightMode) activateLightMode()
            else if (isDarkMode) activateDarkMode()
            else if (isNotSpecified || hasNoSupport) {
              const now = new Date()
              const hour = now.getHours()
              const isNight = hour <= 6 || hour >= 18
              isNight ? activateDarkMode() : activateLightMode()
            }
            window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
              if (saveToLocal.get('theme') === undefined) {
                e.matches ? activateDarkMode() : activateLightMode()
              }
            })
          } else if (t === 'light') activateLightMode()
          else activateDarkMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const fontSizeVal = saveToLocal.get('global-font-size')
    if (fontSizeVal !== undefined) {
      document.documentElement.style.setProperty('--global-font-size', fontSizeVal + 'px')
    }
    })(window)</script><meta name="generator" content="Hexo 5.4.0"><link rel="alternate" href="/atom.xml" title="jzhmcoo1" type="application/atom+xml">
</head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" data-lazy-src="https://jzhmcoo1-1258918430.cos.ap-shanghai.myqcloud.com/markdown/avatar.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">36</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">37</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">9</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-heartbeat"></i><span> 娱乐</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/message/"><i class="fa-fw fa fa-coffee"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-user-friends"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://jzhmcoo1-1258918430.cos.ap-shanghai.myqcloud.com/markdown/20210621082947.png')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">jzhmcoo1</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-heartbeat"></i><span> 娱乐</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/message/"><i class="fa-fw fa fa-coffee"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-user-friends"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">C++OJ环境搭建</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-06-21T00:28:12.000Z" title="发表于 2021-06-21 08:28:12">2021-06-21</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-06-21T00:28:15.000Z" title="更新于 2021-06-21 08:28:15">2021-06-21</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/StudyNotes/">StudyNotes</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">4.3k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>19分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><p>由于之后可能要去复试机考，平时开发时用的都是前端和Node的一套，现在有必要把<code>cpp</code>捡起来了，本文将使用VSCode在MacOS上的<code>cpp17</code>开发环境，以及一些常用的<code>stl</code>和一些常用操作。</p>
<h1 id="环境搭建"><a href="#环境搭建" class="headerlink" title="环境搭建"></a>环境搭建</h1><p>首先要装Xcode，这里就略了</p>
<h2 id="VSCode安装插件"><a href="#VSCode安装插件" class="headerlink" title="VSCode安装插件"></a>VSCode安装插件</h2><ul>
<li><a target="_blank" rel="noopener" href="https://github.com/microsoft/vscode-cpptools">microsoft/vscode-cpptools: Official repository for the Microsoft C/C++ extension for VS Code. (github.com)</a></li>
<li><a target="_blank" rel="noopener" href="https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner">Code Runner - Visual Studio Marketplace</a></li>
</ul>
<h2 id="更改配置"><a href="#更改配置" class="headerlink" title="更改配置"></a>更改配置</h2><p>首先把三个常见的<code>cpp</code>配置文件列一下</p>
<figure class="highlight json"><table><tr><td class="code"><pre><span class="line"><span class="comment">// c_cpp_properties.json</span></span><br><span class="line">&#123;</span><br><span class="line">  <span class="attr">&quot;configurations&quot;</span>: [</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="attr">&quot;name&quot;</span>: <span class="string">&quot;Mac&quot;</span>,</span><br><span class="line">      <span class="attr">&quot;includePath&quot;</span>: [<span class="string">&quot;$&#123;workspaceFolder&#125;/**&quot;</span>],</span><br><span class="line">      <span class="attr">&quot;defines&quot;</span>: [],</span><br><span class="line">      <span class="attr">&quot;macFrameworkPath&quot;</span>: [</span><br><span class="line">        <span class="string">&quot;/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks&quot;</span></span><br><span class="line">      ],</span><br><span class="line">      <span class="attr">&quot;compilerPath&quot;</span>: <span class="string">&quot;/usr/bin/clang&quot;</span>,</span><br><span class="line">      <span class="attr">&quot;cStandard&quot;</span>: <span class="string">&quot;c17&quot;</span>,</span><br><span class="line">      <span class="attr">&quot;cppStandard&quot;</span>: <span class="string">&quot;c++17&quot;</span>,</span><br><span class="line">      <span class="attr">&quot;intelliSenseMode&quot;</span>: <span class="string">&quot;macos-clang-x64&quot;</span></span><br><span class="line">    &#125;</span><br><span class="line">  ],</span><br><span class="line">  <span class="attr">&quot;version&quot;</span>: <span class="number">4</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight json"><table><tr><td class="code"><pre><span class="line"><span class="comment">// launch.json</span></span><br><span class="line">&#123;</span><br><span class="line">  <span class="comment">// 使用 IntelliSense 了解相关属性。</span></span><br><span class="line">  <span class="comment">// 悬停以查看现有属性的描述。</span></span><br><span class="line">  <span class="comment">// 欲了解更多信息，请访问: https://go.microsoft.com/fwlink/?linkid=830387</span></span><br><span class="line">  <span class="attr">&quot;version&quot;</span>: <span class="string">&quot;0.2.0&quot;</span>,</span><br><span class="line">  <span class="attr">&quot;configurations&quot;</span>: [</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="attr">&quot;name&quot;</span>: <span class="string">&quot;clang++ - 生成和调试活动文件&quot;</span>,</span><br><span class="line">      <span class="attr">&quot;type&quot;</span>: <span class="string">&quot;cppdbg&quot;</span>,</span><br><span class="line">      <span class="attr">&quot;request&quot;</span>: <span class="string">&quot;launch&quot;</span>,</span><br><span class="line">      <span class="attr">&quot;program&quot;</span>: <span class="string">&quot;$&#123;fileDirname&#125;/$&#123;fileBasenameNoExtension&#125;&quot;</span>,</span><br><span class="line">      <span class="attr">&quot;args&quot;</span>: [],</span><br><span class="line">      <span class="attr">&quot;stopAtEntry&quot;</span>: <span class="literal">false</span>,</span><br><span class="line">      <span class="attr">&quot;cwd&quot;</span>: <span class="string">&quot;$&#123;fileDirname&#125;&quot;</span>,</span><br><span class="line">      <span class="attr">&quot;environment&quot;</span>: [],</span><br><span class="line">      <span class="attr">&quot;externalConsole&quot;</span>: <span class="literal">true</span>,</span><br><span class="line">      <span class="attr">&quot;MIMode&quot;</span>: <span class="string">&quot;lldb&quot;</span>,</span><br><span class="line">      <span class="attr">&quot;preLaunchTask&quot;</span>: <span class="string">&quot;C/C++: clang++ 生成活动文件&quot;</span></span><br><span class="line">    &#125;</span><br><span class="line">  ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight json"><table><tr><td class="code"><pre><span class="line"><span class="comment">// task.json</span></span><br><span class="line">&#123;</span><br><span class="line">  <span class="attr">&quot;version&quot;</span>: <span class="string">&quot;2.0.0&quot;</span>,</span><br><span class="line">  <span class="attr">&quot;tasks&quot;</span>: [</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="attr">&quot;type&quot;</span>: <span class="string">&quot;cppbuild&quot;</span>,</span><br><span class="line">      <span class="attr">&quot;label&quot;</span>: <span class="string">&quot;C/C++: clang++ 生成活动文件&quot;</span>,</span><br><span class="line">      <span class="attr">&quot;command&quot;</span>: <span class="string">&quot;/usr/bin/clang++&quot;</span>,</span><br><span class="line">      <span class="attr">&quot;args&quot;</span>: [</span><br><span class="line">        <span class="string">&quot;-std=c++17&quot;</span>,</span><br><span class="line">        <span class="string">&quot;-stdlib=libc++&quot;</span>,</span><br><span class="line">        <span class="string">&quot;-g&quot;</span>, <span class="comment">//调试时需要开启</span></span><br><span class="line">        <span class="string">&quot;$&#123;file&#125;&quot;</span>,</span><br><span class="line">        <span class="string">&quot;-o&quot;</span>,</span><br><span class="line">        <span class="string">&quot;$&#123;fileDirname&#125;/$&#123;fileBasenameNoExtension&#125;&quot;</span></span><br><span class="line">      ],</span><br><span class="line">      <span class="attr">&quot;options&quot;</span>: &#123;</span><br><span class="line">        <span class="attr">&quot;cwd&quot;</span>: <span class="string">&quot;$&#123;fileDirname&#125;&quot;</span></span><br><span class="line">      &#125;,</span><br><span class="line">      <span class="attr">&quot;problemMatcher&quot;</span>: [<span class="string">&quot;$gcc&quot;</span>],</span><br><span class="line">      <span class="attr">&quot;group&quot;</span>: &#123;</span><br><span class="line">        <span class="attr">&quot;kind&quot;</span>: <span class="string">&quot;build&quot;</span>,</span><br><span class="line">        <span class="attr">&quot;isDefault&quot;</span>: <span class="literal">true</span></span><br><span class="line">      &#125;,</span><br><span class="line">      <span class="attr">&quot;detail&quot;</span>: <span class="string">&quot;编译器: /usr/bin/clang++&quot;</span></span><br><span class="line">    &#125;</span><br><span class="line">  ]</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="设置选择cpp17"><a href="#设置选择cpp17" class="headerlink" title="设置选择cpp17"></a>设置选择cpp17</h2><p>如果不更改配置的话，使用cpp11+新语法会报错</p>
<h3 id="设置CodeRunner"><a href="#设置CodeRunner" class="headerlink" title="设置CodeRunner"></a>设置CodeRunner</h3><p>进入CodeRunner的设置文件，将<code>code-runner.executorMap</code>属性中的<code>cpp</code>属性的值改为</p>
<figure class="highlight json"><table><tr><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="attr">&quot;code-runner.executorMap&quot;</span>: &#123;</span><br><span class="line">  	<span class="attr">&quot;cpp&quot;</span>: <span class="string">&quot;cd $dir &amp;&amp; g++ -std=c++17 $fileName -o $fileNameWithoutExt &amp;&amp; $dir$fileNameWithoutExt&quot;</span>,</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>也就是多加了一个<code>std=c++17</code></p>
<h3 id="开启CodeRunner命令行"><a href="#开启CodeRunner命令行" class="headerlink" title="开启CodeRunner命令行"></a>开启CodeRunner命令行</h3><p>一般使用CodeRunner直接跑<code>cpp</code>是无法进行输入的，我们开启选项中的如下配置：</p>
<figure class="highlight json"><table><tr><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="attr">&quot;code-runner.runInTerminal&quot;</span>: <span class="literal">true</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>这样就能过使用内置命令行进行交互输入了</p>
<h2 id="进行测试"><a href="#进行测试" class="headerlink" title="进行测试"></a>进行测试</h2><p>我们新建一个<code>cpp</code>程序</p>
<figure class="highlight c++"><table><tr><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  <span class="keyword">long</span> <span class="keyword">long</span> a, b;</span><br><span class="line">  <span class="built_in">cin</span> &gt;&gt; a &gt;&gt; b;</span><br><span class="line">  <span class="built_in">cout</span> &lt;&lt; a + b &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>我们可以使用CodeRunner或者直接按F5运行，这里使用CodeRunner直接运行，可以直接进行输入并且有输出，测试完毕</p>
<h1 id="整理使用Cpp做OJ的常用基础和STL"><a href="#整理使用Cpp做OJ的常用基础和STL" class="headerlink" title="整理使用Cpp做OJ的常用基础和STL"></a>整理使用Cpp做OJ的常用基础和STL</h1><blockquote>
<p><a target="_blank" rel="noopener" href="https://www.runoob.com/cplusplus/cpp-tutorial.html">C++ 教程 | 菜鸟教程 (runoob.com)</a></p>
</blockquote>
<h2 id="数据类型"><a href="#数据类型" class="headerlink" title="数据类型"></a>数据类型</h2><table>
<thead>
<tr>
<th align="center">类型</th>
<th align="center">所占空间</th>
<th align="left">表示范围</th>
</tr>
</thead>
<tbody><tr>
<td align="center"><code>char</code></td>
<td align="center">1B</td>
<td align="left">-128 到 127 或者 0 到 255</td>
</tr>
<tr>
<td align="center"><code>int</code></td>
<td align="center">4B</td>
<td align="left">-2147483648 到 2147483647(即$2^{31}-1$)</td>
</tr>
<tr>
<td align="center"><code>unsigned int</code></td>
<td align="center">4B</td>
<td align="left">0 到 4294967295</td>
</tr>
<tr>
<td align="center"><code>long int</code></td>
<td align="center">8B</td>
<td align="left">-9,223,372,036,854,775,808 到 9,223,372,036,854,775,807</td>
</tr>
<tr>
<td align="center"><code>double</code></td>
<td align="center">8B</td>
<td align="left">双精度型占8 个字节（64位）内存空间，+/- 1.7e +/- 308 (~15 个数字)</td>
</tr>
<tr>
<td align="center"><code>string</code></td>
<td align="center">24B</td>
<td align="left"></td>
</tr>
</tbody></table>
<p>使用以下程序可以打印每个类型的最大值和所占的字节大小</p>
<figure class="highlight c++"><table><tr><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;limits&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">(<span class="keyword">int</span> argc, <span class="keyword">char</span> <span class="keyword">const</span> *argv[])</span> </span>&#123;</span><br><span class="line">  <span class="built_in">cout</span> &lt;&lt; <span class="keyword">sizeof</span>(<span class="keyword">long</span>) &lt;&lt; <span class="built_in">endl</span>;<span class="comment">// 输出8</span></span><br><span class="line">  <span class="built_in">cout</span> &lt;&lt; numeric_limits&lt;<span class="keyword">long</span>&gt;::max() &lt;&lt; <span class="built_in">endl</span>; <span class="comment">// 9223372036854775807</span></span><br><span class="line">  <span class="built_in">cout</span> &lt;&lt; numeric_limits&lt;<span class="keyword">long</span>&gt;::min() &lt;&lt; <span class="built_in">endl</span>; <span class="comment">// -9223372036854775808</span></span><br><span class="line">  <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="位运算符"><a href="#位运算符" class="headerlink" title="位运算符"></a>位运算符</h2><table>
<thead>
<tr>
<th>运算符</th>
<th>描述</th>
<th>例子</th>
</tr>
</thead>
<tbody><tr>
<td>&amp;</td>
<td>按位与</td>
<td><code>0&amp;0=0; 0&amp;1=0; 1&amp;0=0; 1&amp;1=1;</code></td>
</tr>
<tr>
<td>|</td>
<td>按位或</td>
<td>`0</td>
</tr>
<tr>
<td>^</td>
<td>按位异或</td>
<td><code>0^0=0;    0^1=1;    1^0=1;   1^1=0;</code></td>
</tr>
<tr>
<td>~</td>
<td>按位取反</td>
<td><code>~1=-2;    ~0=1;</code></td>
</tr>
<tr>
<td>&gt;&gt;</td>
<td>右移</td>
<td><code>100&gt;&gt;2=25</code></td>
</tr>
<tr>
<td>&lt;&lt;</td>
<td>左移</td>
<td><code>100&lt;&lt;2=400</code></td>
</tr>
</tbody></table>
<h2 id="数学运算"><a href="#数学运算" class="headerlink" title="数学运算"></a>数学运算</h2><p>首先引入<code>&lt;cmath&gt;</code>头文件</p>
<p>一些内置数学函数</p>
<table>
<thead>
<tr>
<th>函数名称</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td><strong>double cos(double);</strong></td>
<td>求弧度角的cos值</td>
</tr>
<tr>
<td><strong>double log(double);</strong></td>
<td>求$ln(x)$</td>
</tr>
<tr>
<td><strong>double pow(double, double);</strong></td>
<td>求$x^y$</td>
</tr>
<tr>
<td><strong>double sqrt(double);</strong></td>
<td>求$\sqrt{x}$</td>
</tr>
<tr>
<td><strong>int abs(int);</strong></td>
<td>求$</td>
</tr>
<tr>
<td><strong>double floor(double);</strong></td>
<td>求$\lfloor x \rfloor$</td>
</tr>
</tbody></table>
<h2 id="数组"><a href="#数组" class="headerlink" title="数组"></a>数组</h2><ul>
<li><p>数组声明：<code>typename name[arraysize]</code>，如：<code>double balance[10];</code></p>
</li>
<li><p>初始化：<code>double balance[5] = &#123;1000.0, 2.0, 3.4, 7.0, 50.0&#125;;</code></p>
</li>
<li><p>向函数的形参传递数组：</p>
<ol>
<li>形参用指针接</li>
<li>形参用已定义大小的数组接</li>
<li>形参用未定义大小的数组接</li>
</ol>
</li>
</ul>
<figure class="highlight c++"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">myFunction</span><span class="params">(<span class="keyword">int</span> *param)</span></span>&#123;&#125;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">myFunction2</span><span class="params">(<span class="keyword">int</span> param[<span class="number">10</span>])</span></span>&#123;&#125;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">myFunction3</span><span class="params">(<span class="keyword">int</span> param[])</span></span>&#123;&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>从函数返回数组<ul>
<li>用指针接，但我看菜鸟上给的例子是用<code>static</code>修饰了一个数组，挺麻烦的，应该不常用</li>
</ul>
</li>
</ul>
<blockquote>
<p>另外，C++ 不支持在函数外返回局部变量的地址，除非定义局部变量为 <strong>static</strong> 变量。</p>
</blockquote>
<h2 id="string类"><a href="#string类" class="headerlink" title="string类"></a>string类</h2><blockquote>
<p><a target="_blank" rel="noopener" href="http://c.biancheng.net/view/400.html">C++ string类（C++字符串）完全攻略 (biancheng.net)</a></p>
</blockquote>
<p>首先引入头文件<code>&lt;string&gt;</code></p>
<h3 id="构造函数"><a href="#构造函数" class="headerlink" title="构造函数"></a>构造函数</h3><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="built_in">string</span> <span class="title">s2</span><span class="params">(<span class="string">&quot;&quot;</span>)</span></span>;       <span class="comment">//构造函数</span></span><br><span class="line"><span class="built_in">cout</span> &lt;&lt; s2 &lt;&lt; <span class="built_in">endl</span>;  <span class="comment">//&quot;&quot;</span></span><br><span class="line"><span class="function"><span class="built_in">string</span> <span class="title">s3</span><span class="params">(<span class="number">4</span>, <span class="string">&#x27;k&#x27;</span>)</span></span>;   <span class="comment">//跟一个char字符</span></span><br><span class="line"><span class="built_in">cout</span> &lt;&lt; s3 &lt;&lt; <span class="built_in">endl</span>;  <span class="comment">// kkkk</span></span><br><span class="line"><span class="function"><span class="built_in">string</span> <span class="title">s4</span><span class="params">(<span class="string">&quot;1234567&quot;</span>, <span class="number">1</span>, <span class="number">3</span>)</span></span>;  <span class="comment">//从index为1开始,长度为3的子串构造新字符串</span></span><br><span class="line"><span class="built_in">cout</span> &lt;&lt; s4 &lt;&lt; <span class="built_in">endl</span>;  <span class="comment">// 234</span></span><br></pre></td></tr></table></figure>

<h3 id="声明和赋值"><a href="#声明和赋值" class="headerlink" title="声明和赋值"></a>声明和赋值</h3><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="built_in">string</span> s1;      <span class="comment">//声明</span></span><br><span class="line">s1 = <span class="string">&quot;123456&quot;</span>;  <span class="comment">//赋值</span></span><br><span class="line"><span class="built_in">string</span> s5 = s1;  <span class="comment">//改变一个字符串不影响另一个</span></span><br><span class="line">s1 = <span class="string">&quot;321&quot;</span>;</span><br><span class="line"><span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;s5 = &quot;</span> &lt;&lt; s5 &lt;&lt; <span class="built_in">endl</span>;  <span class="comment">// 123456</span></span><br><span class="line"><span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;s1 = &quot;</span> &lt;&lt; s1 &lt;&lt; <span class="built_in">endl</span>;  <span class="comment">// 321</span></span><br></pre></td></tr></table></figure>

<h3 id="求长度"><a href="#求长度" class="headerlink" title="求长度"></a>求长度</h3><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="built_in">cout</span> &lt;&lt; s5.length() &lt;&lt; <span class="built_in">endl</span>;  <span class="comment">// 6</span></span><br><span class="line"><span class="built_in">cout</span> &lt;&lt; s5.size() &lt;&lt; <span class="built_in">endl</span>;    <span class="comment">// 6</span></span><br></pre></td></tr></table></figure>

<h3 id="字符串连接"><a href="#字符串连接" class="headerlink" title="字符串连接"></a>字符串连接</h3><p>可以使用<code>+=</code>或者成员函数<code>append</code>，会改变原字符串</p>
<figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line">string s1(&quot;123&quot;), s2(&quot;abc&quot;);</span><br><span class="line">s1.append(s2);  <span class="comment">// s1 = &quot;123abc&quot;</span></span><br><span class="line">s1.append(s2, <span class="number">1</span>, <span class="number">2</span>);  <span class="comment">// s1 = &quot;123abcbc&quot;</span></span><br><span class="line">s1.append(<span class="number">3</span>, <span class="string">&#x27;K&#x27;</span>);  <span class="comment">// s1 = &quot;123abcbcKKK&quot;</span></span><br><span class="line">s1.append(<span class="string">&quot;ABCDE&quot;</span>, <span class="number">2</span>, <span class="number">3</span>);  <span class="comment">// s1 = &quot;123abcbcKKKCDE&quot;，添加 &quot;ABCDE&quot; 的子串(2, 3)</span></span><br></pre></td></tr></table></figure>

<h3 id="字符串比较"><a href="#字符串比较" class="headerlink" title="字符串比较"></a>字符串比较</h3><p>可以使用$≥,≤,==,!=,&gt;,&lt;$也可以用成员函数<code>compare()</code></p>
<p>compare 成员函数有以下返回值：</p>
<ul>
<li>小于 0 表示当前的字符串小；</li>
<li>等于 0 表示两个字符串相等；</li>
<li>大于 0 表示另一个字符串小。</li>
</ul>
<figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line">string s1(&quot;hello&quot;), s2(&quot;hello, world&quot;);</span><br><span class="line"><span class="keyword">int</span> n = s1.compare(s2);</span><br><span class="line">n = s1.compare(<span class="number">1</span>, <span class="number">2</span>, s2, <span class="number">0</span>, <span class="number">3</span>);  <span class="comment">//比较s1的子串 (1,2) 和s2的子串 (0,3)</span></span><br><span class="line">n = s1.compare(<span class="number">0</span>, <span class="number">2</span>, s2);  <span class="comment">// 比较s1的子串 (0,2) 和 s2</span></span><br><span class="line">n = s1.compare(<span class="string">&quot;Hello&quot;</span>);</span><br><span class="line">n = s1.compare(<span class="number">1</span>, <span class="number">2</span>, <span class="string">&quot;Hello&quot;</span>);  <span class="comment">//比较 s1 的子串(1,2)和&quot;Hello”</span></span><br><span class="line">n = s1.compare(<span class="number">1</span>, <span class="number">2</span>, <span class="string">&quot;Hello&quot;</span>, <span class="number">1</span>, <span class="number">2</span>);  <span class="comment">//比较 s1 的子串(1,2)和 &quot;Hello&quot; 的子串(1,2)</span></span><br></pre></td></tr></table></figure>

<h3 id="求子串"><a href="#求子串" class="headerlink" title="求子串"></a>求子串</h3><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="built_in">string</span> <span class="title">s6</span><span class="params">(<span class="string">&quot;I&#x27;mxxxxs6&quot;</span>)</span></span>;</span><br><span class="line"><span class="built_in">string</span> s7 = s6.substr(<span class="number">2</span>, <span class="number">3</span>);    <span class="comment">// 从index为2的地方，截3的长度</span></span><br><span class="line"><span class="built_in">string</span> s8 = s6.substr(<span class="number">2</span>, <span class="number">100</span>);  <span class="comment">// 长度超了也只会截到最后</span></span><br><span class="line"><span class="built_in">string</span> s9 = s6.substr(<span class="number">2</span>);       <span class="comment">//长度没写就截到最后</span></span><br><span class="line"><span class="built_in">cout</span> &lt;&lt; s7 &lt;&lt; <span class="built_in">endl</span>;             <span class="comment">// mxx</span></span><br><span class="line"><span class="built_in">cout</span> &lt;&lt; s8 &lt;&lt; <span class="built_in">endl</span>;             <span class="comment">// mxxxxs6</span></span><br><span class="line"><span class="built_in">cout</span> &lt;&lt; s9 &lt;&lt; <span class="built_in">endl</span>;             <span class="comment">// mxxxxs6</span></span><br></pre></td></tr></table></figure>

<h3 id="交换"><a href="#交换" class="headerlink" title="交换"></a>交换</h3><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="built_in">string</span> <span class="title">s10</span><span class="params">(<span class="string">&quot;10&quot;</span>)</span></span>;</span><br><span class="line"><span class="function"><span class="built_in">string</span> <span class="title">s11</span><span class="params">(<span class="string">&quot;11&quot;</span>)</span></span>;</span><br><span class="line">s10.swap(s11);</span><br><span class="line"><span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;s10 = &quot;</span> &lt;&lt; s10 &lt;&lt; <span class="built_in">endl</span>;  <span class="comment">// 11</span></span><br><span class="line"><span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;s11 = &quot;</span> &lt;&lt; s11 &lt;&lt; <span class="built_in">endl</span>;  <span class="comment">// 10</span></span><br></pre></td></tr></table></figure>

<h3 id="查找子串"><a href="#查找子串" class="headerlink" title="查找子串"></a>查找子串</h3><blockquote>
<p><code>string</code> 类有一些查找子串和字符的成员函数，它们的返回值都是子串或字符在 <code>string</code> 对象字符串中的位置（即下标）。如果查不到，则返回 <code>string::npos</code>。<code>string::npos</code> 是在 <code>string</code> 类中定义的一个静态常量。</p>
</blockquote>
<ul>
<li><code>find</code>：从前往后查找子串或字符出现的位置。</li>
<li><code>rfind</code>：从后往前查找子串或字符出现的位置。</li>
<li><code>find_first_of</code>：从前往后查找何处出现另一个字符串中包含的字符。例如：</li>
<li><code>s1.find_first_of(&quot;abc&quot;)</code>; //查找s1中第一次出现”abc”中任一字符的位置</li>
<li><code>find_last_of</code>：从后往前查找何处出现另一个字符串中包含的字符。</li>
<li><code>find_first_not_of</code>：从前往后查找何处出现另一个字符串中没有包含的字符。</li>
<li><code>find_last_not_of</code>：从后往前查找何处出现另一个字符串中没有包含的字符。</li>
</ul>
<figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;string&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span> </span>&#123;</span><br><span class="line">  <span class="function"><span class="built_in">string</span> <span class="title">s1</span><span class="params">(<span class="string">&quot;Source Code&quot;</span>)</span></span>;</span><br><span class="line">  <span class="keyword">int</span> n;</span><br><span class="line">  <span class="keyword">if</span> ((n = s1.find(<span class="string">&#x27;u&#x27;</span>)) != <span class="built_in">string</span>::npos)  <span class="comment">//查找 u 出现的位置</span></span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;1) &quot;</span> &lt;&lt; n &lt;&lt; <span class="string">&quot;,&quot;</span> &lt;&lt; s1.substr(n) &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">  <span class="comment">//输出 l)2,urce Code</span></span><br><span class="line">  <span class="keyword">if</span> ((n = s1.find(<span class="string">&quot;Source&quot;</span>, <span class="number">3</span>)) == <span class="built_in">string</span>::npos)</span><br><span class="line">    <span class="comment">//从下标3开始查找&quot;Source&quot;，找不到</span></span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;2) &quot;</span></span><br><span class="line">         &lt;&lt; <span class="string">&quot;Not Found&quot;</span> &lt;&lt; <span class="built_in">endl</span>;  <span class="comment">//输出 2) Not Found</span></span><br><span class="line">  <span class="keyword">if</span> ((n = s1.find(<span class="string">&quot;Co&quot;</span>)) != <span class="built_in">string</span>::npos)</span><br><span class="line">    <span class="comment">//查找子串&quot;Co&quot;。能找到，返回&quot;Co&quot;的位置</span></span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;3) &quot;</span> &lt;&lt; n &lt;&lt; <span class="string">&quot;, &quot;</span> &lt;&lt; s1.substr(n) &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">  <span class="comment">//输出 3) 7, Code</span></span><br><span class="line">  <span class="keyword">if</span> ((n = s1.find_first_of(<span class="string">&quot;ceo&quot;</span>)) != <span class="built_in">string</span>::npos)</span><br><span class="line">    <span class="comment">//查找第一次出现或 &#x27;c&#x27;、&#x27;e&#x27;或&#x27;o&#x27;的位置</span></span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;4) &quot;</span> &lt;&lt; n &lt;&lt; <span class="string">&quot;, &quot;</span> &lt;&lt; s1.substr(n) &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">  <span class="comment">//输出 4) l, ource Code</span></span><br><span class="line">  <span class="keyword">if</span> ((n = s1.find_last_of(<span class="string">&#x27;e&#x27;</span>)) != <span class="built_in">string</span>::npos)</span><br><span class="line">    <span class="comment">//查找最后一个 &#x27;e&#x27; 的位置</span></span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;5) &quot;</span> &lt;&lt; n &lt;&lt; <span class="string">&quot;, &quot;</span> &lt;&lt; s1.substr(n) &lt;&lt; <span class="built_in">endl</span>;  <span class="comment">//输出 5) 10, e</span></span><br><span class="line">  <span class="keyword">if</span> ((n = s1.find_first_not_of(<span class="string">&quot;eou&quot;</span>, <span class="number">1</span>)) != <span class="built_in">string</span>::npos)</span><br><span class="line">    <span class="comment">//从下标1开始查找第一次出现非 &#x27;e&#x27;、&#x27;o&#x27; 或 &#x27;u&#x27; 字符的位置</span></span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;6) &quot;</span> &lt;&lt; n &lt;&lt; <span class="string">&quot;, &quot;</span> &lt;&lt; s1.substr(n) &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">  <span class="comment">//输出 6) 3, rce Code</span></span><br><span class="line">  <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="替换子串"><a href="#替换子串" class="headerlink" title="替换子串"></a>替换子串</h3><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;string&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">(<span class="keyword">int</span> argc, <span class="keyword">char</span> <span class="keyword">const</span> *argv[])</span> </span>&#123;</span><br><span class="line">  <span class="function"><span class="built_in">string</span> <span class="title">s1</span><span class="params">(<span class="string">&quot;Real Steel&quot;</span>)</span></span>;</span><br><span class="line">  s1.replace(<span class="number">1</span>, <span class="number">3</span>, <span class="string">&quot;123456&quot;</span>, <span class="number">2</span>,</span><br><span class="line">             <span class="number">4</span>);       <span class="comment">//用 &quot;123456&quot; 的子串(2,4) 替换 s1 的子串(1,3)</span></span><br><span class="line">  <span class="built_in">cout</span> &lt;&lt; s1 &lt;&lt; <span class="built_in">endl</span>;  <span class="comment">//输出 R3456 Steel</span></span><br><span class="line">  <span class="function"><span class="built_in">string</span> <span class="title">s2</span><span class="params">(<span class="string">&quot;Harry Potter&quot;</span>)</span></span>;</span><br><span class="line">  s2.replace(<span class="number">2</span>, <span class="number">3</span>, <span class="number">5</span>, <span class="string">&#x27;0&#x27;</span>);  <span class="comment">//用 5 个 &#x27;0&#x27; 替换子串(2,3)</span></span><br><span class="line">  <span class="built_in">cout</span> &lt;&lt; s2 &lt;&lt; <span class="built_in">endl</span>;        <span class="comment">//输出 Ha00000 Potter</span></span><br><span class="line">  <span class="keyword">int</span> n = s2.find(<span class="string">&quot;00000&quot;</span>);  <span class="comment">//查找子串 &quot;00000&quot; 的位置，n=2</span></span><br><span class="line">  <span class="built_in">cout</span> &lt;&lt; n &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">  s2.replace(n, <span class="number">5</span>, <span class="string">&quot;XXX&quot;</span>);  <span class="comment">//将子串(n,5)替换为&quot;XXX&quot;</span></span><br><span class="line">  <span class="built_in">cout</span> &lt;&lt; s2 &lt;&lt; <span class="built_in">endl</span>;       <span class="comment">//输出 HaXXX Potter</span></span><br><span class="line">  <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="删除子串"><a href="#删除子串" class="headerlink" title="删除子串"></a>删除子串</h3><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="built_in">string</span> <span class="title">s1</span><span class="params">(<span class="string">&quot;Real Steel&quot;</span>)</span></span>;</span><br><span class="line">s1.erase(<span class="number">1</span>, <span class="number">3</span>);  <span class="comment">//删除子串(1, 3)，此后 s1 = &quot;R Steel&quot;</span></span><br><span class="line">s1.erase(<span class="number">5</span>);  <span class="comment">//删除下标5及其后面的所有字符，此后 s1 = &quot;R Ste&quot;</span></span><br></pre></td></tr></table></figure>

<h3 id="插入子串"><a href="#插入子串" class="headerlink" title="插入子串"></a>插入子串</h3><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line">string s1(&quot;Limitless&quot;), s2(&quot;00&quot;);</span><br><span class="line">s1.insert(<span class="number">2</span>, <span class="string">&quot;123&quot;</span>);  <span class="comment">//在下标 2 处插入字符串&quot;123&quot;，s1 = &quot;Li123mitless&quot;</span></span><br><span class="line">s1.insert(<span class="number">3</span>, s2);  <span class="comment">//在下标 2 处插入 s2 , s1 = &quot;Li10023mitless&quot;</span></span><br><span class="line">s1.insert(<span class="number">3</span>, <span class="number">5</span>, <span class="string">&#x27;X&#x27;</span>);  <span class="comment">//在下标 3 处插入 5 个 &#x27;X&#x27;，s1 = &quot;Li1XXXXX0023mitless&quot;</span></span><br></pre></td></tr></table></figure>

<h3 id="用-STL-算法操作-string-对象"><a href="#用-STL-算法操作-string-对象" class="headerlink" title="用 STL 算法操作 string 对象"></a>用 STL 算法操作 string 对象</h3><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;algorithm&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;string&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span> </span>&#123;</span><br><span class="line">  <span class="function"><span class="built_in">string</span> <span class="title">s</span><span class="params">(<span class="string">&quot;afgcbed&quot;</span>)</span></span>;</span><br><span class="line">  <span class="built_in">string</span>::iterator p = find(s.begin(), s.end(), <span class="string">&#x27;c&#x27;</span>);</span><br><span class="line">  <span class="built_in">cout</span> &lt;&lt; *p &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">  <span class="keyword">if</span> (p != s.end()) <span class="built_in">cout</span> &lt;&lt; p - s.begin() &lt;&lt; <span class="built_in">endl</span>;  <span class="comment">//输出 3</span></span><br><span class="line">  sort(s.begin(), s.end());</span><br><span class="line">  <span class="built_in">cout</span> &lt;&lt; s &lt;&lt; <span class="built_in">endl</span>;  <span class="comment">//输出 abcdefg</span></span><br><span class="line">  next_permutation(s.begin(), s.end());</span><br><span class="line">  <span class="built_in">cout</span> &lt;&lt; s &lt;&lt; <span class="built_in">endl</span>;  <span class="comment">//输出 abcdegf</span></span><br><span class="line">  <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="自定义数据结构"><a href="#自定义数据结构" class="headerlink" title="自定义数据结构"></a>自定义数据结构</h2><p>可以使用<code>typedef</code>最简单</p>
<figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;string&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">typedef</span> <span class="class"><span class="keyword">struct</span> <span class="title">Book</span> &#123;</span></span><br><span class="line">  <span class="keyword">int</span> book_id;</span><br><span class="line">  <span class="built_in">string</span> book_title;</span><br><span class="line">  <span class="built_in">string</span> author;</span><br><span class="line">  <span class="built_in">string</span> subject;</span><br><span class="line">&#125; Book;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">(<span class="keyword">int</span> argc, <span class="keyword">char</span> <span class="keyword">const</span> *argv[])</span> </span>&#123;</span><br><span class="line">  Book book1;</span><br><span class="line">  book1.book_title = <span class="string">&quot;JavaScript高级程序设计&quot;</span>; <span class="comment">// 写着cpp我还在想着js</span></span><br><span class="line">  book1.author = <span class="string">&quot;Nicolas&quot;</span>;</span><br><span class="line">  book1.subject = <span class="string">&quot;Web Development&quot;</span>;</span><br><span class="line">  <span class="built_in">cout</span> &lt;&lt; book1.book_title &lt;&lt; <span class="built_in">endl</span></span><br><span class="line">       &lt;&lt; book1.author &lt;&lt; <span class="built_in">endl</span></span><br><span class="line">       &lt;&lt; book1.subject &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">  <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="动态内存"><a href="#动态内存" class="headerlink" title="动态内存"></a>动态内存</h2><p>使用<code>new</code>申请，使用<code>delete</code>释放</p>
<h3 id="一维数组"><a href="#一维数组" class="headerlink" title="一维数组"></a>一维数组</h3><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">(<span class="keyword">int</span> argc, <span class="keyword">char</span> <span class="keyword">const</span> *argv[])</span> </span>&#123;</span><br><span class="line">  <span class="keyword">int</span> m; <span class="built_in">cin</span> &gt;&gt; m;</span><br><span class="line">  <span class="keyword">int</span> *<span class="built_in">array</span> = <span class="keyword">new</span> <span class="keyword">int</span>[m]; <span class="comment">// 动态分配,数组长度为 m</span></span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; m; i++) &#123; <span class="built_in">cin</span> &gt;&gt; <span class="built_in">array</span>[i]; &#125;</span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; m; i++) &#123; <span class="built_in">cout</span> &lt;&lt; <span class="built_in">array</span>[i] &lt;&lt; <span class="string">&quot; &quot;</span>; &#125; <span class="built_in">cout</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">  <span class="keyword">delete</span>[] <span class="built_in">array</span>; <span class="comment">// 释放内存</span></span><br><span class="line">  <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="二维数组"><a href="#二维数组" class="headerlink" title="二维数组"></a>二维数组</h3><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="keyword">int</span> **p;</span><br><span class="line"><span class="keyword">int</span> i, j;  <span class="comment">// p[4][8]</span></span><br><span class="line"><span class="comment">//开始分配4行8列的二维数据</span></span><br><span class="line">p = <span class="keyword">new</span> <span class="keyword">int</span> *[<span class="number">4</span>];</span><br><span class="line"><span class="keyword">for</span> (i = <span class="number">0</span>; i &lt; <span class="number">4</span>; i++) &#123;</span><br><span class="line">  p[i] = <span class="keyword">new</span> <span class="keyword">int</span>[<span class="number">8</span>];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> (i = <span class="number">0</span>; i &lt; <span class="number">4</span>; i++) &#123;</span><br><span class="line">  <span class="keyword">for</span> (j = <span class="number">0</span>; j &lt; <span class="number">8</span>; j++) &#123;</span><br><span class="line">    p[i][j] = j * i;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//打印数据</span></span><br><span class="line"><span class="keyword">for</span> (i = <span class="number">0</span>; i &lt; <span class="number">4</span>; i++) &#123;</span><br><span class="line">  <span class="keyword">for</span> (j = <span class="number">0</span>; j &lt; <span class="number">8</span>; j++) &#123;</span><br><span class="line">    <span class="keyword">if</span> (j == <span class="number">0</span>) <span class="built_in">cout</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; p[i][j] &lt;&lt; <span class="string">&quot;\t&quot;</span>;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//开始释放申请的堆</span></span><br><span class="line"><span class="keyword">for</span> (i = <span class="number">0</span>; i &lt; <span class="number">4</span>; i++) &#123;</span><br><span class="line">  <span class="keyword">delete</span>[] p[i];</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">delete</span>[] p;</span><br></pre></td></tr></table></figure>

<h2 id="vector"><a href="#vector" class="headerlink" title="vector"></a>vector</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;vector&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">(<span class="keyword">int</span> argc, <span class="keyword">char</span> <span class="keyword">const</span> *argv[])</span> </span>&#123;</span><br><span class="line">  <span class="built_in">vector</span>&lt;<span class="keyword">int</span>&gt; a;  <span class="comment">//声明</span></span><br><span class="line">  <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;vector a&#x27;s length = &quot;</span> &lt;&lt; a.size() &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">  <span class="comment">// 插入5个值</span></span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; <span class="number">5</span>; i++) &#123;</span><br><span class="line">    a.push_back(i);</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;vector a&#x27;s length = &quot;</span> &lt;&lt; a.size() &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">  <span class="comment">// 使用迭代器 iterator 访问值</span></span><br><span class="line">  <span class="built_in">vector</span>&lt;<span class="keyword">int</span>&gt;::iterator v = a.begin();</span><br><span class="line">  <span class="keyword">while</span> (v != a.end()) &#123;</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;value of v = &quot;</span> &lt;&lt; *v &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    v++;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  <span class="function"><span class="built_in">vector</span>&lt;<span class="keyword">int</span>&gt; <span class="title">b</span><span class="params">(a.begin(), a.end() - <span class="number">1</span>)</span></span>;  <span class="comment">//构造新的vector</span></span><br><span class="line">  <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;vector b&#x27;s length = &quot;</span> &lt;&lt; b.size() &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">  <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="unordered-map散列表"><a href="#unordered-map散列表" class="headerlink" title="unordered_map散列表"></a>unordered_map散列表</h2><p>引入头文件<code>&lt;unordered_map&gt;</code></p>
<figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;unordered_map&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">(<span class="keyword">int</span> argc, <span class="keyword">char</span> <span class="keyword">const</span> *argv[])</span> </span>&#123;</span><br><span class="line">  <span class="comment">// 初始化散列表</span></span><br><span class="line">  <span class="built_in">unordered_map</span>&lt;<span class="built_in">string</span>, <span class="keyword">int</span>&gt; dic;</span><br><span class="line"></span><br><span class="line">  <span class="comment">// 添加 key -&gt; value 键值对</span></span><br><span class="line">  dic[<span class="string">&quot;小力&quot;</span>] = <span class="number">10001</span>;</span><br><span class="line">  dic[<span class="string">&quot;小特&quot;</span>] = <span class="number">10002</span>;</span><br><span class="line">  dic[<span class="string">&quot;小扣&quot;</span>] = <span class="number">10003</span>;</span><br><span class="line"></span><br><span class="line">  <span class="comment">// 从姓名查找学号</span></span><br><span class="line">  <span class="built_in">cout</span> &lt;&lt; dic.find(<span class="string">&quot;小力&quot;</span>)-&gt;second &lt;&lt; <span class="built_in">endl</span>;  <span class="comment">//打印值</span></span><br><span class="line">  <span class="built_in">cout</span> &lt;&lt; dic.find(<span class="string">&quot;小力&quot;</span>)-&gt;first &lt;&lt; <span class="built_in">endl</span>;   <span class="comment">//打印键&quot;小力&quot;</span></span><br><span class="line">  <span class="built_in">cout</span> &lt;&lt; dic.find(<span class="string">&quot;小力&quot;</span>)-&gt;first &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">  ;  <span class="comment">// -&gt; 10001</span></span><br><span class="line">  <span class="built_in">cout</span> &lt;&lt; dic.find(<span class="string">&quot;小特&quot;</span>)-&gt;second &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">  ;  <span class="comment">// -&gt; 10002</span></span><br><span class="line">  <span class="built_in">cout</span> &lt;&lt; dic.find(<span class="string">&quot;小扣&quot;</span>)-&gt;second &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">  ;  <span class="comment">// -&gt; 10003</span></span><br><span class="line">  <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="priority-queue优先队列-堆"><a href="#priority-queue优先队列-堆" class="headerlink" title="priority_queue优先队列(堆)"></a>priority_queue优先队列(堆)</h2><blockquote>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/weixin_36888577/article/details/79937886">c++优先队列(priority_queue)用法详解_吕白_的博客-CSDN博客_c++优先队列</a></p>
</blockquote>
<p>引入头文件<code>&lt;queue&gt;</code></p>
<p>和<code>queue</code>不同的地方在于，可以自定义其中数据的优先级，让优先级高的排在队列前面优先出队。优先队列具有队列的所有特性，包括基本操作，只是在这基础上添加了内部的一个排序，本质是一个堆实现的</p>
<table>
<thead>
<tr>
<th align="center">方法</th>
<th>含义</th>
</tr>
</thead>
<tbody><tr>
<td align="center"><code>top</code></td>
<td>访问队头元素</td>
</tr>
<tr>
<td align="center"><code>empty</code></td>
<td>队列是否为空</td>
</tr>
<tr>
<td align="center"><code>size</code></td>
<td>返回队列内元素的个数</td>
</tr>
<tr>
<td align="center"><code>push</code></td>
<td>插入队尾并排序</td>
</tr>
<tr>
<td align="center"><code>emplace</code></td>
<td>原地构造一个元素并插入队列</td>
</tr>
<tr>
<td align="center"><code>pop</code></td>
<td>弹出队头元素</td>
</tr>
<tr>
<td align="center"><code>swap</code></td>
<td>交换内容</td>
</tr>
</tbody></table>
<figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">// 升序队列(小根堆)</span></span><br><span class="line"><span class="built_in">priority_queue</span> &lt;<span class="keyword">int</span>,<span class="built_in">vector</span>&lt;<span class="keyword">int</span>&gt;,greater&lt;<span class="keyword">int</span>&gt;&gt; heap;</span><br><span class="line"><span class="comment">// 大根堆</span></span><br><span class="line"><span class="built_in">priority_queue</span> &lt;<span class="keyword">int</span>,<span class="built_in">vector</span>&lt;<span class="keyword">int</span>&gt;,less&lt;<span class="keyword">int</span>&gt;&gt; heap2;</span><br></pre></td></tr></table></figure>

<h2 id="pair"><a href="#pair" class="headerlink" title="pair"></a>pair</h2><blockquote>
<p><a target="_blank" rel="noopener" href="https://leetcode-cn.com/problems/sliding-window-maximum/">239. 滑动窗口最大值 - 力扣（LeetCode） (leetcode-cn.com)</a></p>
</blockquote>
<p>这道题的解法用到了<code>pair</code>、<code>priority_queue</code>、<code>deque</code>，正好来整理一下</p>
<blockquote>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/sevenjoin/article/details/81937695">C++ pair的基本用法总结（整理）_sevenjoin的博客-CSDN博客_c++ pair</a></p>
<p>pair是将2个数据组合成一组数据，当需要这样的需求时就可以使用pair，如stl中的map就是将key和value放在一起来保存。另一个应用是，当一个函数需要返回2个数据的时候，可以选择pair。 pair的实现是一个结构体，主要的两个成员变量是first second 因为是使用struct不是class，所以可以直接使用pair的成员变量。</p>
</blockquote>
<p>使用<code>pair</code>需要引入头文件<code>utility</code></p>
<h3 id="解法一"><a href="#解法一" class="headerlink" title="解法一"></a>解法一</h3><p>这道题的解法一用到了<code>pair</code>和<code>priority_queue</code>。大根堆的队头元素为最大值，如果存储的元素只是值的话，我们不知道什么时候让它出队，所有可以在每个结点中存入一个<code>pair</code>，放数组的下标和元素值，如果窗口滑出了返回，就可以删除当前堆的最大值</p>
<figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="built_in">vector</span>&lt;<span class="keyword">int</span>&gt; <span class="title">maxSlidingWindow</span><span class="params">(<span class="built_in">vector</span>&lt;<span class="keyword">int</span>&gt;&amp; nums, <span class="keyword">int</span> k)</span> </span>&#123;</span><br><span class="line">  <span class="keyword">int</span> n = nums.size();</span><br><span class="line">  <span class="built_in">priority_queue</span>&lt;<span class="built_in">pair</span>&lt;<span class="keyword">int</span>, <span class="keyword">int</span>&gt;&gt; q;</span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; k; ++i) &#123;</span><br><span class="line">    q.emplace(nums[i], i);  <span class="comment">// 原地构造pair并入队</span></span><br><span class="line">  &#125;</span><br><span class="line">  <span class="built_in">vector</span>&lt;<span class="keyword">int</span>&gt; ans = &#123;q.top().first&#125;;</span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">int</span> i = k; i &lt; n; ++i) &#123;</span><br><span class="line">    q.emplace(nums[i], i);</span><br><span class="line">    <span class="comment">// 队列中的最大值的下标超出了窗口的范围,需要出队</span></span><br><span class="line">    <span class="keyword">while</span> (q.top().second &lt;= i - k) &#123;</span><br><span class="line">      q.pop();</span><br><span class="line">    &#125;</span><br><span class="line">    ans.push_back(q.top().first);</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> ans;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="解法二"><a href="#解法二" class="headerlink" title="解法二"></a>解法二</h3><p>方法二用到了双端队列。向后遍历元素时，如果我们的队列不为空，入队新元素时，将队尾和待入队元素进行比较，如果待入队元素$&gt;$队尾元素，要先出队队尾元素，直到队伍为空或者队尾元素大于待入队元素，此时将新元素入队</p>
<p>与方法一中相同的是，此时的最大值可能在滑动窗口左边界的左侧，并且随着窗口向右移动，它永远不可能出现在滑动窗口中了。因此我们还需要不断从队首弹出元素，直到队首元素在窗口中为止。</p>
<figure class="highlight c++"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="built_in">vector</span>&lt;<span class="keyword">int</span>&gt; <span class="title">maxSlidingWindow</span><span class="params">(<span class="built_in">vector</span>&lt;<span class="keyword">int</span>&gt;&amp; nums, <span class="keyword">int</span> k)</span> </span>&#123;</span><br><span class="line">  <span class="keyword">int</span> n = nums.size();</span><br><span class="line">  <span class="built_in">deque</span>&lt;<span class="keyword">int</span>&gt; q;</span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; k; ++i) &#123;</span><br><span class="line">    <span class="keyword">while</span> (!q.empty() &amp;&amp; nums[i] &gt;= nums[q.back()]) &#123;</span><br><span class="line">      q.pop_back();</span><br><span class="line">    &#125;</span><br><span class="line">    q.push_back(i);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  <span class="built_in">vector</span>&lt;<span class="keyword">int</span>&gt; ans = &#123;nums[q.front()]&#125;;</span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">int</span> i = k; i &lt; n; ++i) &#123;</span><br><span class="line">    <span class="keyword">while</span> (!q.empty() &amp;&amp; nums[i] &gt;= nums[q.back()]) &#123;</span><br><span class="line">      q.pop_back();</span><br><span class="line">    &#125;</span><br><span class="line">    q.push_back(i);</span><br><span class="line">    <span class="keyword">while</span> (q.front() &lt;= i - k) &#123;</span><br><span class="line">      q.pop_front();</span><br><span class="line">    &#125;</span><br><span class="line">    ans.push_back(nums[q.front()]);</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> ans;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>未完待续，接着刷题，碰到了继续整理</p>
<blockquote>
<p>找到一个STL容器的整理： <a target="_blank" rel="noopener" href="https://www.jianshu.com/p/497843e403b4">C++进阶-STL容器，你看我就够了 - 简书 (jianshu.com)</a></p>
</blockquote>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">lixing</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://www.lihangzhu.com/2021/06/21/Cpp-OJ-Environment/">https://www.lihangzhu.com/2021/06/21/Cpp-OJ-Environment/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://www.lihangzhu.com" target="_blank">jzhmcoo1</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/OJ/">OJ</a><a class="post-meta__tags" href="/tags/C/">C++</a></div><div class="post_share"><div class="social-share" data-image="https://jzhmcoo1-1258918430.cos.ap-shanghai.myqcloud.com/markdown/20210621082947.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2021/06/26/Css-Core-Concepts/"><img class="prev-cover" data-lazy-src="https://gitee.com/jzhmcoo1/jzhmcoo1picrepo/raw/master/img/css.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">css关键概念</div></div></a></div><div class="next-post pull-right"><a href="/2021/06/20/Browser-Cache/"><img class="next-cover" data-lazy-src="https://jzhmcoo1-1258918430.cos.ap-shanghai.myqcloud.com/markdown/20210620222035.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">浏览器的强缓存和协商缓存</div></div></a></div></nav><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-info-avatar is-center"><img class="avatar-img" data-lazy-src="https://jzhmcoo1-1258918430.cos.ap-shanghai.myqcloud.com/markdown/avatar.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">lixing</div><div class="author-info__description">👨🏻‍💻 好好学习，天天敲代码 👩🏻‍💻</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">36</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">37</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">9</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/jzhmcoo1"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/jzhmcoo1" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:jzhmzlxocoo1@gmail.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a><a class="social-icon" href="/atom.xml" target="_blank" title="RSS"><i class="fa fa-rss"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">真正的大师,永远都怀着一颗学徒的心</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA"><span class="toc-number">1.</span> <span class="toc-text">环境搭建</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#VSCode%E5%AE%89%E8%A3%85%E6%8F%92%E4%BB%B6"><span class="toc-number">1.1.</span> <span class="toc-text">VSCode安装插件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%9B%B4%E6%94%B9%E9%85%8D%E7%BD%AE"><span class="toc-number">1.2.</span> <span class="toc-text">更改配置</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%AE%BE%E7%BD%AE%E9%80%89%E6%8B%A9cpp17"><span class="toc-number">1.3.</span> <span class="toc-text">设置选择cpp17</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%AE%BE%E7%BD%AECodeRunner"><span class="toc-number">1.3.1.</span> <span class="toc-text">设置CodeRunner</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%BC%80%E5%90%AFCodeRunner%E5%91%BD%E4%BB%A4%E8%A1%8C"><span class="toc-number">1.3.2.</span> <span class="toc-text">开启CodeRunner命令行</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%BF%9B%E8%A1%8C%E6%B5%8B%E8%AF%95"><span class="toc-number">1.4.</span> <span class="toc-text">进行测试</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%95%B4%E7%90%86%E4%BD%BF%E7%94%A8Cpp%E5%81%9AOJ%E7%9A%84%E5%B8%B8%E7%94%A8%E5%9F%BA%E7%A1%80%E5%92%8CSTL"><span class="toc-number">2.</span> <span class="toc-text">整理使用Cpp做OJ的常用基础和STL</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">2.1.</span> <span class="toc-text">数据类型</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%8D%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">2.2.</span> <span class="toc-text">位运算符</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B0%E5%AD%A6%E8%BF%90%E7%AE%97"><span class="toc-number">2.3.</span> <span class="toc-text">数学运算</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B0%E7%BB%84"><span class="toc-number">2.4.</span> <span class="toc-text">数组</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#string%E7%B1%BB"><span class="toc-number">2.5.</span> <span class="toc-text">string类</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0"><span class="toc-number">2.5.1.</span> <span class="toc-text">构造函数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A3%B0%E6%98%8E%E5%92%8C%E8%B5%8B%E5%80%BC"><span class="toc-number">2.5.2.</span> <span class="toc-text">声明和赋值</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B1%82%E9%95%BF%E5%BA%A6"><span class="toc-number">2.5.3.</span> <span class="toc-text">求长度</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%BF%9E%E6%8E%A5"><span class="toc-number">2.5.4.</span> <span class="toc-text">字符串连接</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%AF%94%E8%BE%83"><span class="toc-number">2.5.5.</span> <span class="toc-text">字符串比较</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B1%82%E5%AD%90%E4%B8%B2"><span class="toc-number">2.5.6.</span> <span class="toc-text">求子串</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BA%A4%E6%8D%A2"><span class="toc-number">2.5.7.</span> <span class="toc-text">交换</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9F%A5%E6%89%BE%E5%AD%90%E4%B8%B2"><span class="toc-number">2.5.8.</span> <span class="toc-text">查找子串</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9B%BF%E6%8D%A2%E5%AD%90%E4%B8%B2"><span class="toc-number">2.5.9.</span> <span class="toc-text">替换子串</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%A0%E9%99%A4%E5%AD%90%E4%B8%B2"><span class="toc-number">2.5.10.</span> <span class="toc-text">删除子串</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%8F%92%E5%85%A5%E5%AD%90%E4%B8%B2"><span class="toc-number">2.5.11.</span> <span class="toc-text">插入子串</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%94%A8-STL-%E7%AE%97%E6%B3%95%E6%93%8D%E4%BD%9C-string-%E5%AF%B9%E8%B1%A1"><span class="toc-number">2.5.12.</span> <span class="toc-text">用 STL 算法操作 string 对象</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%87%AA%E5%AE%9A%E4%B9%89%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84"><span class="toc-number">2.6.</span> <span class="toc-text">自定义数据结构</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8A%A8%E6%80%81%E5%86%85%E5%AD%98"><span class="toc-number">2.7.</span> <span class="toc-text">动态内存</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%80%E7%BB%B4%E6%95%B0%E7%BB%84"><span class="toc-number">2.7.1.</span> <span class="toc-text">一维数组</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BA%8C%E7%BB%B4%E6%95%B0%E7%BB%84"><span class="toc-number">2.7.2.</span> <span class="toc-text">二维数组</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#vector"><span class="toc-number">2.8.</span> <span class="toc-text">vector</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#unordered-map%E6%95%A3%E5%88%97%E8%A1%A8"><span class="toc-number">2.9.</span> <span class="toc-text">unordered_map散列表</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#priority-queue%E4%BC%98%E5%85%88%E9%98%9F%E5%88%97-%E5%A0%86"><span class="toc-number">2.10.</span> <span class="toc-text">priority_queue优先队列(堆)</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#pair"><span class="toc-number">2.11.</span> <span class="toc-text">pair</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%A7%A3%E6%B3%95%E4%B8%80"><span class="toc-number">2.11.1.</span> <span class="toc-text">解法一</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%A7%A3%E6%B3%95%E4%BA%8C"><span class="toc-number">2.11.2.</span> <span class="toc-text">解法二</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2021/08/01/%E8%B7%A8%E5%9F%9F/" title="跨域问题"><img data-lazy-src="https://jzhmcoo1-1258918430.cos.ap-shanghai.myqcloud.com/markdown/20210801204426-browser.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="跨域问题"/></a><div class="content"><a class="title" href="/2021/08/01/%E8%B7%A8%E5%9F%9F/" title="跨域问题">跨域问题</a><time datetime="2021-08-01T12:42:27.000Z" title="发表于 2021-08-01 20:42:27">2021-08-01</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/06/26/Css-Core-Concepts/" title="css关键概念"><img data-lazy-src="https://gitee.com/jzhmcoo1/jzhmcoo1picrepo/raw/master/img/css.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="css关键概念"/></a><div class="content"><a class="title" href="/2021/06/26/Css-Core-Concepts/" title="css关键概念">css关键概念</a><time datetime="2021-06-26T02:53:41.000Z" title="发表于 2021-06-26 10:53:41">2021-06-26</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/06/21/Cpp-OJ-Environment/" title="C++OJ环境搭建"><img data-lazy-src="https://jzhmcoo1-1258918430.cos.ap-shanghai.myqcloud.com/markdown/20210621082947.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="C++OJ环境搭建"/></a><div class="content"><a class="title" href="/2021/06/21/Cpp-OJ-Environment/" title="C++OJ环境搭建">C++OJ环境搭建</a><time datetime="2021-06-21T00:28:12.000Z" title="发表于 2021-06-21 08:28:12">2021-06-21</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/06/20/Browser-Cache/" title="浏览器的强缓存和协商缓存"><img data-lazy-src="https://jzhmcoo1-1258918430.cos.ap-shanghai.myqcloud.com/markdown/20210620222035.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="浏览器的强缓存和协商缓存"/></a><div class="content"><a class="title" href="/2021/06/20/Browser-Cache/" title="浏览器的强缓存和协商缓存">浏览器的强缓存和协商缓存</a><time datetime="2021-06-20T14:18:05.000Z" title="发表于 2021-06-20 22:18:05">2021-06-20</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/06/17/Sorting/" title="排序算法汇总"><img data-lazy-src="https://jzhmcoo1-1258918430.cos.ap-shanghai.myqcloud.com/markdown/20210617235208-sorting.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="排序算法汇总"/></a><div class="content"><a class="title" href="/2021/06/17/Sorting/" title="排序算法汇总">排序算法汇总</a><time datetime="2021-06-17T15:53:46.000Z" title="发表于 2021-06-17 23:53:46">2021-06-17</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2021 By lixing</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text"><a target="_blank" rel="noopener" href="http://www.beian.miit.gov.cn/"><img class="icp-icon" src="/images/icp.png"><span>备案号：沪ICP备20019376号-1</span></a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="font-plus" type="button" title="放大字体"><i class="fas fa-plus"></i></button><button id="font-minus" type="button" title="缩小字体"><i class="fas fa-minus"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="/js/search/local-search.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"><script>if (!window.MathJax) {
  window.MathJax = {
    loader: {
      source: {
        '[tex]/amsCd': '[tex]/amscd'
      }
    },
    tex: {
      inlineMath: [ ['$','$'], ["\\(","\\)"]],
      tags: 'ams'
    },
    options: {
      renderActions: {
        findScript: [10, doc => {
          for (const node of document.querySelectorAll('script[type^="math/tex"]')) {
            const display = !!node.type.match(/; *mode=display/)
            const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display)
            const text = document.createTextNode('')
            node.parentNode.replaceChild(text, node)
            math.start = {node: text, delim: '', n: 0}
            math.end = {node: text, delim: '', n: 0}
            doc.math.push(math)
          }
        }, ''],
        addClass: [200,() => {
          document.querySelectorAll('mjx-container:not([display=\'true\']').forEach( node => {
            const target = node.parentNode
            if (!target.classList.contains('has-jax')) {
              target.classList.add('mathjax-overflow')
            }
          })
        }, '', false]
      }
    }
  }
  
  const script = document.createElement('script')
  script.src = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js'
  script.id = 'MathJax-script'
  script.async = true
  document.head.appendChild(script)
} else {
  MathJax.startup.document.state(0)
  MathJax.texReset()
  MathJax.typeset()
}</script><script>function loadValine () {
  function initValine () {
    let initData = {
      el: '#vcomment',
      appId: 'eLIUaG0QmIrM06RLR7ib4AWK-gzGzoHsz',
      appKey: '4WOHEFT9gxfwKDLWQ3Dlc1xi',
      placeholder: '英雄别着急走,留下姓名~',
      avatar: 'monsterid',
      meta: 'nick,mail,link'.split(','),
      pageSize: '10',
      lang: 'zh-CN',
      recordIP: false,
      serverURLs: '',
      emojiCDN: 'https://i0.hdslb.com/bfs/emote/',
      emojiMaps: {"2020":"dc709fac0d361370bcf0d36d32adb97df7c95824.png@112w_112h.png","热词系列_知识增加":"142409b595982b8210b2958f3d340f3b47942645.png@112w_112h.png","热词系列_梦幻联动":"4809416be5ca787c2ec3e897e4fd022a58da6e0e.png@112w_112h.png","热词系列_希望没事":"6c0d2e6c486d1ba5afd6204a96e102652464a01d.png@112w_112h.png","热词系列_泪目":"bba3703ab90b7d16fe9dbcb85ed949db687f8331.png@112w_112h.png","热词系列_保护":"55f8f6445ca7c3170cdfc5b16036abf639ce9b57.png@112w_112h.png","热词系列_害怕":"d77e2de26da143249f0c0ad7a608c27152c985bf.png@112w_112h.png","热词系列_爱了爱了":"2a165b555ba20391316366c664ed7891883dc5aa.png@112w_112h.png","热词系列_吹爆":"b528220f9c37256ed6a37f05bf118e44b08b81e5.png@112w_112h.png","热词系列_三连":"21f15fe11b7a84d2f2121c16dec50a4e4556f865.png@112w_112h.png","热词系列_可以":"e08543c71202b36c590094417fcfbb80c3506cd8.png@112w_112h.png","热词系列_打卡":"a9cf77c78e1b9b40aa3ed4862402fba008ee2f51.png@112w_112h.png","热词系列_妙啊":"0e98299d7decf5eaffad854977946075c3e91cb8.png@112w_112h.png","热词系列_这次一定":"a01ca28923daa7cc896c42f27deb4914e20dd572.png@112w_112h.png","热词系列_AWSL":"c37f88cf799f9badf9d84b7671dc3dd98c0fc0c2.png@112w_112h.png","热词系列_递话筒":"98e6950e39fbb4dd1c576042063ca632074070ba.png@112w_112h.png","热词系列_你细品":"535e00658e7e47966f154d3a167fa2365ebc4321.png@112w_112h.png","热词系列_咕咕":"d8065c2e7ce48c929317a94553499a46fecc262a.png@112w_112h.png","热词系列_你可真星":"54c8ddff400abfe388060cabfbb579280fdea1be.png@112w_112h.png","热词系列_标准结局":"3de98174b510cf7dc5fd1bd08c5d881065e79137.png@112w_112h.png","热词系列_危":"5cc6c3357c4df544dd8de9d5c5c0cec97c7c9a56.png@112w_112h.png","热词系列_张三":"255a938f39cea625032b6650036b31aa26c50a3c.png@112w_112h.png","热词系列_害":"cbe798a194612958537c5282fcca7c3bcd2aa15c.png@112w_112h.png","热词系列_我裂开了":"29bd57ec4e8952880fea6c9e47aee924e91f10c4.png@112w_112h.png","热词系列_有内味了":"7ca61680a905b5b6e2e335c630e725b648b03b4d.png@112w_112h.png","热词系列_猛男必看":"c97064450528a0e45c7e7c365a15fbb13fd61d8c.png@112w_112h.png","热词系列_奥力给":"c9b8683827ec6c00fea5327c9bec14f581cef2aa.png@112w_112h.png","热词系列_问号":"c1d1e76c12180adc8558f47006fe0e7ded4154bb.png@112w_112h.png","热词系列_我哭了":"9e0b3877d649aaf6538fbdd3f937e240a9d808e4.png@112w_112h.png","热词系列_高产":"9db817cba4a7f4a42398f3b2ec7c0a8e0c247c42.png@112w_112h.png","热词系列_我酸了":"a8cbf3f6b8cd9377eeb15b9172f3cd683b2e4650.png@112w_112h.png","热词系列_真香":"e68497c775feaac1c3b1a6cd63a50cfb11b767c4.png@112w_112h.png","热词系列_我全都要":"d424d1ad8d14c1c9b8367842bc68c658b9229bc1.png@112w_112h.png","热词系列_神仙UP":"a49e0d0db1e7d35a0f7411be13208951ab448f03.png@112w_112h.png","热词系列_你币有了":"84820c2b147a8ca02f3c4006b63f76c6313cbfa0.png@112w_112h.png","热词系列_不愧是你":"9ff2e356797c57ee3b1675ade0883d2d2247be9b.png@112w_112h.png","热词系列_锤":"35668cc12ae25b9545420e4a85bf21a0bfc03e5d.png@112w_112h.png","热词系列_秀":"50782fbf5d9b7f48f9467b5c53932981e321eedc.png@112w_112h.png","热词系列_爷关更":"faad40c56447f1f8abcb4045c17ce159d113d1fd.png@112w_112h.png","热词系列_有生之年":"f41fdafe2d0fbb8e8bc1598d2cf37e355560103a.png@112w_112h.png","热词系列_镇站之宝":"24e7a6a6e6383c987215fb905e3ee070aca259b5.png@112w_112h.png","热词系列_我太南了":"a523f3e4c63e4db1232365765d0ec452f83be97e.png@112w_112h.png","热词系列_完结撒花":"ea9db62ff5bca8e069cd70c4233353a802835422.png@112w_112h.png","热词系列_大师球":"f30089248dd137c568edabcb07cf67e0f6e98cf3.png@112w_112h.png","热词系列_知识盲区":"ccc94600b321a28116081e49ecedaa4ee8728312.png@112w_112h.png","热词系列_“狼火”":"33ccd3617bfa89e9d1498b13b7542b63f163e5de.png@112w_112h.png","口罩":"3ad2f66b151496d2a5fb0a8ea75f32265d778dd3.png@112w_112h.png","微笑":"685612eadc33f6bc233776c6241813385844f182.png@112w_112h.png","笑":"81edf17314cea3b48674312b4364df44d5c01f17.png@112w_112h.png","呲牙":"b5a5898491944a4268360f2e7a84623149672eb6.png@112w_112h.png","OK":"4683fd9ffc925fa6423110979d7dcac5eda297f4.png@112w_112h.png","星星眼":"63c9d1a31c0da745b61cdb35e0ecb28635675db2.png@112w_112h.png","哦呼":"362bded07ea5434886271d23fa25f5d85d8af06c.png@112w_112h.png","嫌弃":"de4c0783aaa60ec03de0a2b90858927bfad7154b.png@112w_112h.png","喜欢":"8a10a4d73a89f665feff3d46ca56e83dc68f9eb8.png@112w_112h.png","酸了":"92b1c8cbceea3ae0e8e32253ea414783e8ba7806.png@112w_112h.png","大哭":"2caafee2e5db4db72104650d87810cc2c123fc86.png@112w_112h.png","害羞":"9d2ec4e1fbd6cb1b4d12d2bbbdd124ccb83ddfda.png@112w_112h.png","无语":"44667b7d9349957e903b1b62cb91fb9b13720f04.png@112w_112h.png","疑惑":"b7840db4b1f9f4726b7cb23c0972720c1698d661.png@112w_112h.png","调皮":"8290b7308325e3179d2154327c85640af1528617.png@112w_112h.png","喜极而泣":"485a7e0c01c2d70707daae53bee4a9e2e31ef1ed.png@112w_112h.png","奸笑":"bb84906573472f0a84cebad1e9000eb6164a6f5a.png@112w_112h.png","偷笑":"6c49d226e76c42cd8002abc47b3112bc5a92f66a.png@112w_112h.png","大笑":"ca94ad1c7e6dac895eb5b33b7836b634c614d1c0.png@112w_112h.png","阴险":"ba8d5f8e7d136d59aab52c40fd3b8a43419eb03c.png@112w_112h.png","捂脸":"6921bb43f0c634870b92f4a8ad41dada94a5296d.png@112w_112h.png","囧":"12e41d357a9807cc80ef1e1ed258127fcc791424.png@112w_112h.png","呆":"33ad6000d9f9f168a0976bc60937786f239e5d8c.png@112w_112h.png","抠鼻":"cb89184c97e3f6d50acfd7961c313ce50360d70f.png@112w_112h.png","惊喜":"0afecaf3a3499479af946f29749e1a6c285b6f65.png@112w_112h.png","惊讶":"f8e9a59cad52ae1a19622805696a35f0a0d853f3.png@112w_112h.png","笑哭":"c3043ba94babf824dea03ce500d0e73763bf4f40.png@112w_112h.png","妙啊":"b4cb77159d58614a9b787b91b1cd22a81f383535.png@112w_112h.png","doge":"bba7c12aa51fed0199c241465560dfc2714c593e.png@112w_112h.png","滑稽":"d15121545a99ac46774f1f4465b895fe2d1411c3.png@112w_112h.png","吃瓜":"4191ce3c44c2b3df8fd97c33f85d3ab15f4f3c84.png@112w_112h.png","打call":"431432c43da3ee5aab5b0e4f8931953e649e9975.png@112w_112h.png","点赞":"1a67265993913f4c35d15a6028a30724e83e7d35.png@112w_112h.png","鼓掌":"895d1fc616b4b6c830cf96012880818c0e1de00d.png@112w_112h.png","尴尬":"cb321684ed5ce6eacdc2699092ab8fe7679e4fda.png@112w_112h.png","冷":"cb0ebbd0668640f07ebfc0e03f7a18a8cd00b4ed.png@112w_112h.png","灵魂出窍":"43d3db7d97343c01b47e22cfabeca84b4251f35a.png@112w_112h.png","委屈":"d2f26cbdd6c96960320af03f5514c5b524990840.png@112w_112h.png","傲娇":"010540d0f61220a0db4922e4a679a1d8eca94f4e.png@112w_112h.png","疼":"905fd9a99ec316e353b9bd4ecd49a5f0a301eabf.png@112w_112h.png","吓":"9c10c5ebc7bef27ec641b8a1877674e0c65fea5d.png@112w_112h.png","生病":"0f25ce04ae1d7baf98650986454c634f6612cb76.png@112w_112h.png","吐":"06946bfe71ac48a6078a0b662181bb5cad09decc.png@112w_112h.png","嘘声":"e64af664d20716e090f10411496998095f62f844.png@112w_112h.png","捂眼":"c5c6d6982e1e53e478daae554b239f2b227b172b.png@112w_112h.png","思考":"cfa9b7e89e4bfe04bbcd34ccb1b0df37f4fa905c.png@112w_112h.png","再见":"fc510306bae26c9aec7e287cdf201ded27b065b9.png@112w_112h.png","翻白眼":"eba54707c7168925b18f6f8b1f48d532fe08c2b1.png@112w_112h.png","哈欠":"888d877729cbec444ddbd1cf4c9af155a7a06086.png@112w_112h.png","奋斗":"bb2060c15dba7d3fd731c35079d1617f1afe3376.png@112w_112h.png","墨镜":"3a03aebfc06339d86a68c2d893303b46f4b85771.png@112w_112h.png","撇嘴":"531863568e5668c5ac181d395508a0eeb1f0cda4.png@112w_112h.png","难过":"a651db36701610aa70a781fa98c07c9789b11543.png@112w_112h.png","抓狂":"4c87afff88c22439c45b79e9d2035d21d5622eba.png@112w_112h.png","生气":"3195714219c4b582a4fb02033dd1519913d0246d.png@112w_112h.png","视频卫星":"dce6fc7d6dfeafff01241924db60f8251cca5307.png@112w_112h.png","11周年":"d3b2d5dc028c75ae4df379f4c3afbe186d0f6f9b.png@112w_112h.png","鸡腿":"c7860392815d345fa69c4f00ef18d67dccfbd574.png@112w_112h.png","干杯":"8da12d5f55a2c7e9778dcc05b40571979fe208e6.png@112w_112h.png","爱心":"ed04066ea7124106d17ffcaf75600700e5442f5c.png@112w_112h.png","锦鲤":"643d6c19c8164ffd89e3e9cdf093cf5d773d979c.png@112w_112h.png","胜利":"b49fa9f4b1e7c3477918153b82c60b114d87347c.png@112w_112h.png","加油":"c7aaeacb21e107292d3bb053e5abde4a4459ed30.png@112w_112h.png","保佑":"fafe8d3de0dc139ebe995491d2dac458a865fb30.png@112w_112h.png","抱拳":"89516218158dbea18ab78e8873060bf95d33bbbe.png@112w_112h.png","响指":"1b5c53cf14336903e1d2ae3527ca380a1256a077.png@112w_112h.png","支持":"3c210366a5585706c09d4c686a9d942b39feeb50.png@112w_112h.png","拥抱":"41780a4254750cdaaccb20735730a36044e98ef3.png@112w_112h.png","怪我咯":"07cc6077f7f7d75b8d2c722dd9d9828a9fb9e46d.png@112w_112h.png","跪了":"f2b3aee7e521de7799d4e3aa379b01be032698ac.png@112w_112h.png","黑洞":"e90ec4c799010f25391179118ccd9f66b3b279ba.png@112w_112h.png","老鼠":"8e6fb491eb1bb0d5862e7ec8ccf9a3da12b6c155.png@112w_112h.png","福到了":"5de5373d354c373cf1617b6b836f3a8d53c5a655.png@112w_112h.png","加油武汉":"eb966aaa5b690d3f9308a9f936f5b5a72a7f956b.png@112w_112h.png"},
      enableQQ: false,
      path: window.location.pathname,
    }

    if (true) { 
      initData.requiredFields= ('nick,mail'.split(','))
    }
    
    if (false) {
      const otherData = false
      initData = Object.assign(initData, otherData)
    }
    
    const valine = new Valine(initData)
  }

  if (typeof Valine === 'function') initValine() 
  else getScript('https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js').then(initValine)
}

if ('Valine' === 'Valine' || !false) {
  if (false) btf.loadComment(document.getElementById('vcomment'),loadValine)
  else setTimeout(loadValine, 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script></div><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="false" data-click="false"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>